from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views import generic
from django.views.generic import TemplateView, DeleteView, CreateView, UpdateView
from gerencia.models import Usuario, Morador

# Create your views here.
class IndexView(TemplateView):
    template_name = 'tp2/login.html'

class ListView(generic.ListView):
    template_name = 'tp2/listar.html'
    context_object_name = 'moradores'

    def get_queryset(self):
        """
        Return the last five published polls (not including those set to be
        published in the future).
        """
        return Morador.objects.all()
    
class DeleteMoradorView(DeleteView):
    model = Morador
    template_name = 'tp2/deletar.html'
    
    def get_success_url(self):
        return reverse('list')

class CreateMoradorView(CreateView):

    model = Morador
    fields = ['nome', 'apelido', 'rg', 'cpf']
    template_name = 'tp2/editar.html'

    def get_success_url(self):
        return reverse('list')

    
class UpdateMoradorView(UpdateView):

    model = Morador
    fields = ['nome', 'apelido', 'rg', 'cpf']
    template_name = 'tp2/editar.html'

    def get_success_url(self):
        return reverse('list')